﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using QLPM.DTO;

namespace QLPM.DAO
{
    public class TaiKhoanDAO
    {

        DataProvider provider;

        public TaiKhoanDAO()
        {
            provider = new DataProvider();
        }
        public List<TaiKhoan> DanhSachTaiKhoan()
        {
            String sql = "select * from TAIKHOAN";
            provider = new DataProvider("TAIKHOAN", sql);
            DataTable dt = provider;
            List<TaiKhoan> ds = new List<TaiKhoan>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TaiKhoan TK = new TaiKhoan();
                TK.TenDangNhap = dt.Rows[i]["TenDangNhap"].ToString();
                TK.MaDangNhap = dt.Rows[i][2].ToString();//"MaDangNhap"
                TK.HoTen = dt.Rows[i]["HoTen"].ToString();
                TK.ChucVu = dt.Rows[i]["ChucVu"].ToString();
                ds.Add(TK);
            }
            return ds;

        }
        public int ThemTaiKhoan(TaiKhoan TK)
        {
            String sql = String.Format("insert into TAIKHOAN(TenDangNhap,MatkhauDangNhap,HoTen,ChucVu,Email) values('{0}','{1}','{2}','{3}','{4}')", TK.TenDangNhap, TK.MaDangNhap, TK.HoTen, TK.ChucVu, TK.Email);
            return provider.Excute_Non_Query(sql);
        }
    }
}
